package com.jt.controller;

import com.jt.pojo.ItemCat;
import com.jt.service.ItemCatService;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/itemCat")
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;

    @GetMapping("/findItemCatList/{level}")
    public SysResult findItemCat(@PathVariable Integer level){
     List<ItemCat> list= itemCatService.findItemCat(level);
        return SysResult.success(list);
    }

    @PutMapping("/status/{id}/{status}")
    public SysResult updateItemCatStatus(ItemCat itemCat){
        itemCatService.updateItemCatStatus(itemCat);
        return SysResult.success();
    }

    @PostMapping("/saveItemCat")
    public SysResult saveItemCat(@RequestBody ItemCat itemCat){
        itemCatService.saveItemCat(itemCat.setStatus(true));
        return SysResult.success();
    }

    @DeleteMapping("/deleteItemCat")
    public SysResult deleteItemCat(ItemCat itemCat){
        itemCatService.deleteItemCat(itemCat);
        return SysResult.success();
    }

    @PutMapping("/updateItemCat")
public  SysResult updateItemCat( @RequestBody ItemCat itemCat){
        itemCatService.updateItemCat(itemCat);
        return  SysResult.success();
    }
}
